<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>产品信息提交</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #e9ecef;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background: #ffffff;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 600px;
        }
        h1 {
            font-size: 26px;
            margin-bottom: 20px;
            color: #333;
            text-align: center;
        }
        .form-row {
            display: flex;
            gap: 20px;
            margin-bottom: 20px;
        }
        .form-group {
            flex: 1;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #495057;
        }
        input[type="text"] {
            width: 100%;
            padding: 12px;
            border: 1px solid #ced4da;
            border-radius: 8px;
            box-sizing: border-box;
            transition: border-color 0.3s, box-shadow 0.3s;
        }
        input[type="text"]:focus {
            border-color: #80bdff;
            box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.25);
            outline: none;
        }
        button {
            background-color: #007bff;
            color: #ffffff;
            border: none;
            padding: 12px 24px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 18px;
            transition: background-color 0.3s, transform 0.2s;
        }
        button:hover {
            background-color: #0056b3;
            transform: scale(1.05);
        }
        button:active {
            transform: scale(1.02);
        }
    </style>
</head>
<body>
<div class="container">
    <h1>建模信息提交</h1>
    <form id="productForm">
        <div class="form-row">
            <div class="form-group">
                <label for="partNumber">
                    型号 <span style="color: red;">*</span>
                </label>
                <input type="text" id="partNumber" name="partNumber" required>
            </div>
            <div class="form-group">
                <label for="orgName">厂商</label>
                <input type="text" id="orgName" name="orgName">
            </div>
        </div>
        <div class="form-row">
            <div class="form-group">
                <label for="datasheet">产品手册</label>
                <input type="text" id="datasheet" name="datasheet">
            </div>
            <div class="form-group">
                <label for="remarks">备注</label>
                <input type="text" id="remarks" name="remarks">
            </div>
        </div>
        <button type="submit">提交</button>
    </form>
</div>

<script>
    document.getElementById('productForm').addEventListener('submit', function(event) {
        event.preventDefault(); // 阻止表单的默认提交行为

        // 获取表单数据
        const formData = new FormData(this);

        // 将 FormData 转换为 JSON 对象
        const data = {};
        formData.forEach((value, key) => {
            data[key] = value;
        });

        // 发送数据到后端接口
        fetch('/resource/modelApplication', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json' // 设置 Content-Type 为 application/json
            },
            body: JSON.stringify(data) // 转换为 JSON 字符串
        })
            .then(response => response.json()) // 处理响应
            .then(data => {
                console.log('Success:', data);
                alert('提交成功！');
            })
            .catch(error => {
                console.error('Error:', error);
                alert('提交失败，请重试。');
            });
    });
</script>
</body>
</html>